package com.jss.lanouhn.fristapp.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.jss.lanouhn.fristapp.Interface.OnItemClickLister;
import com.jss.lanouhn.fristapp.R;
import com.jss.lanouhn.fristapp.modles.homeModles.BelowLunBoTu;
import com.squareup.picasso.Picasso;

/**
 * Created by lanouhn on 16/8/24.
 */
public class HomeSmallAdapter extends RecyclerView.Adapter<HomeSmallAdapter.SmallViewHolder>{
    private Context context;
    private BelowLunBoTu belowLunBoTu;

    private OnItemClickLister mOnItemClickLister;

    public  void setOnItemClickLister(OnItemClickLister mOnItemClickLister){
        this.mOnItemClickLister=mOnItemClickLister;
    }

    public HomeSmallAdapter(Context context, BelowLunBoTu belowLunBoTu) {
        this.context = context;
        this.belowLunBoTu = belowLunBoTu;
    }

    @Override
    public SmallViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.item_home_small,null);
        SmallViewHolder holder=new SmallViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final SmallViewHolder holder, final int position) {
        BelowLunBoTu.DataBean.SecondaryBannersBean bean=
                belowLunBoTu.getData().getSecondary_banners().get(position);
        Picasso.with(context).load(bean.getImage_url()).into(holder.view);
        if(mOnItemClickLister!=null){
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos=holder.getLayoutPosition();
                    mOnItemClickLister.onItemClick(holder.itemView,pos);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return belowLunBoTu.getData().getSecondary_banners().size();
    }

    public class SmallViewHolder extends RecyclerView.ViewHolder{
        private ImageView view;
        public SmallViewHolder(View itemView) {
            super(itemView);
            view= (ImageView) itemView.findViewById(R.id.iv_item_small);
        }
    }
}
